package app

import (
	"context"
	"github.com/jinzhu/copier"

	"web_server/internal/svc"
	"web_server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShortPoetryLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShortPoetryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShortPoetryLogic {
	return &ShortPoetryLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShortPoetryLogic) ShortPoetry() (*types.ShortPoetryResponse, error) {
	shortPoetry, err := l.svcCtx.MysqlClient.ShortPoetryModel.RandomFindOne(l.ctx)
	if err != nil {
		return nil, err
	}
	var result types.ShortPoetryResponse = types.ShortPoetryResponse{}
	copyErr := copier.Copy(&result, &shortPoetry)
	if copyErr != nil {
		return nil, copyErr
	}
	return &result, nil
}
